package org.scc.action;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.scc.model.ArticleType;
import org.scc.service.ArticleService;
import org.scc.service.ArticleTypeService;

public class IndexAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private ArticleTypeService articleTypeService;
	private ArticleService articleService;
	private List<ArticleType> articleTypes;
	
	private Map<ArticleType, List> indexArticles;
	public IndexAction(){
		articleTypeService = new ArticleTypeService();
		articleService = new ArticleService();
	}
	
	public String initIndexPage(){
		indexArticles = new TreeMap<ArticleType, List>(new Comparator<ArticleType>() {
			@Override
			public int compare(ArticleType at1, ArticleType at2) {
				return at1.getSort() - at2.getSort();
			}
		});
		articleTypes = articleTypeService.findIndexShow();
		for(ArticleType at : articleTypes){
			indexArticles.put(at, articleService.findIndexArticleByType(at.getId()) );
		}
		return SUCCESS;
	}

	public Map<ArticleType, List> getIndexArticles() {
		return indexArticles;
	}

	public void setIndexArticles(Map<ArticleType, List> indexArticles) {
		this.indexArticles = indexArticles;
	}

	public List<ArticleType> getArticleTypes() {
		return articleTypes;
	}

	public void setArticleTypes(List<ArticleType> articleTypes) {
		this.articleTypes = articleTypes;
	}
	
}
